import { getToken } from '~/apis'
import { loginUrl } from '~/config'

let token = ''
export async function useLogin() {
  if (token)
    return token
  const [error, { code, ...data }] = await getToken()
  if (error || code != 100) {
    location.href = loginUrl
    return
  }
  if (code == 100) {
    token = data.token
    return token
  }
}
